package com.czy.owner.ui.store.storeviewholder;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.StoreActivityModel;
import com.czy.owner.utils.TimeUtils;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;


/**
 * Created wangyang on 2016/6/14.
 */
public class StoreTvAndVideoViewHolder extends BaseViewHolder<StoreActivityModel.StoreList> {
    private TextView tv_Title;
    private ImageView img_Bg;
    private ImageView img_Play;
    private TextView tv_Time;
    private TextView tv_store_describe;
    private Context ctx;

    public StoreTvAndVideoViewHolder(ViewGroup parent, Context ctx) {
        super(parent, R.layout.item_store_type_tvandvideo);
        tv_Title = $(R.id.tv_title);
        img_Play = $(R.id.img_play);
        img_Bg = $(R.id.img_bg);
        tv_Time = $(R.id.tv_time);
        tv_store_describe = $(R.id.tv_store_describe);
        this.ctx = ctx;
    }

    @Override
    public void setData(StoreActivityModel.StoreList model) {

        try {
            tv_Title.setText(model.getTitle());
            tv_store_describe.setText(model.getContent());
            String time = TimeUtils.formatTimeDifference2(Long.parseLong(model.getCreateTime()));
            tv_Time.setText(time);
            getVideoUrl(model);
            GlideUtils.loadImage(ctx, listvideo.get(0), img_Bg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            },R.mipmap.default_banner,R.mipmap.default_banner);
        }catch (Exception e){

        }
    }



    private List<String> listvideo = null;
    private void getVideoUrl(StoreActivityModel.StoreList model){
        listvideo =new ArrayList<>();
        for(int i=0;i<model.getResList().size();i++) {
            if (model.getResList().get(i).getResType().equals("video")) {
                listvideo.add(model.getResList().get(i).getThumbnailUrl());
                if(listvideo.size()==1){
                    return;
                }
            }
        }
    }
}
